package com.slg.android.manyanime.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by E540 on 2015/3/14.
 */
public class Comment {
    /**
     * 评论id
     */
    private String id;
    /**
     * 评论类型
     */
    private String module;
    /**
     * 动画ID
     */
    private String mid;
    private String content;
    private String toUid;
    /**
     * 评论人ID
     */
    private String fromUid;
    private String goodNum;
    private String replyNum;
    private String createTime;
    private String isPraise;
    private WatchUser fromUser;

    public static List<Comment> parseData(String json){
        ArrayList<Comment> commentList = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray list = jsonObject.getJSONArray("list");
            for (int i = 0; i < list.length(); i++) {
                Comment c = new Comment();
                JSONObject comment = list.getJSONObject(i);
                c.setId(comment.getString("id"));
                c.setModule(comment.getString("module"));
                c.setMid(comment.getString("mid"));
                c.setContent(comment.getString("content"));
                c.setToUid(comment.getString("to_uid"));
                c.setFromUid(comment.getString("from_uid"));
                c.setGoodNum(comment.getString("good_num"));
                c.setReplyNum(comment.getString("reply_num"));
                c.setCreateTime(comment.getString("create_time"));
                c.setIsPraise(comment.getString("is_praise"));
                WatchUser watchUser = new WatchUser();
                watchUser.parseJson(comment.getJSONObject("from_user"));
                c.setFromUser(watchUser);
                commentList.add(c);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


        return commentList;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getMid() {
        return mid;
    }

    public void setMid(String mid) {
        this.mid = mid;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getToUid() {
        return toUid;
    }

    public void setToUid(String toUid) {
        this.toUid = toUid;
    }

    public String getFromUid() {
        return fromUid;
    }

    public void setFromUid(String fromUid) {
        this.fromUid = fromUid;
    }

    public String getGoodNum() {
        return goodNum;
    }

    public void setGoodNum(String goodNum) {
        this.goodNum = goodNum;
    }

    public String getReplyNum() {
        return replyNum;
    }

    public void setReplyNum(String replyNum) {
        this.replyNum = replyNum;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getIsPraise() {
        return isPraise;
    }

    public void setIsPraise(String isPraise) {
        this.isPraise = isPraise;
    }

    public WatchUser getFromUser() {
        return fromUser;
    }

    public void setFromUser(WatchUser fromUser) {
        this.fromUser = fromUser;
    }
}
